package com.appkubes.mall.admin.application.customer.collect.service.impl;

import com.appkubes.mall.admin.application.customer.collect.dao.CustomerCollectDao;
import com.appkubes.mall.admin.application.customer.collect.entity.dto.CustomerCollectUpsertDTO;
import com.appkubes.mall.admin.application.customer.collect.entity.vo.CustomerCollectUpsertVO;
import com.appkubes.mall.admin.application.customer.collect.service.CustomerCollectService;
import com.appkubes.mall.admin.application.customer.collect.entity.dto.GoodsCollectDTO;
import com.appkubes.mall.core.entity.MallCustomerCollect;
import com.appkubes.mall.core.service.impl.BaseMallCustomerCollectServiceImpl;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @Author: Lin Jiaming
 * @Date: 2020/3/4 15:54
 * @Description:
 */
@Service
public class CustomerCollectServiceImpl extends BaseMallCustomerCollectServiceImpl implements CustomerCollectService {

    @Autowired
    CustomerCollectDao customerCollectDao;

    @Override
    public List<GoodsCollectDTO> goodsCollectList(String customerKey, Integer sort, Page pageInfo) {
        return customerCollectDao.goodsCollectList(customerKey, sort, pageInfo);
    }

    @Override
    @Transactional
    public CustomerCollectUpsertDTO upsert(CustomerCollectUpsertVO upsertVO) {
        MallCustomerCollect customerCollect = new MallCustomerCollect();
        BeanUtils.copyProperties(upsertVO, customerCollect);
        customerCollect.setAppKey(null);
        this.saveOrUpdate(customerCollect);

        CustomerCollectUpsertDTO collectUpsertDTO = new CustomerCollectUpsertDTO();
        collectUpsertDTO.setCollectKey(customerCollect.getCollectKey());
        return collectUpsertDTO;
    }
}
